<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="template.xhtml">
	<ui:define name="corpo">
		<h2>Vagas</h2>

		<h:panelGrid rendered="#{loginBean.pessoa.perfil != ALUNO}">
			<p:commandButton value="Adicionar vaga"
				oncomplete="dialogCadastroVaga.show()" style="align: left"
				rendered="#{loginBean.pessoa.perfil == 'ADM'}" />

			<p:commandButton value="Adicionar vaga"
				oncomplete="dialogCadastroVaga.show()" style="align: left"
				rendered="#{loginBean.pessoa.perfil == 'PARCEIRO'}">
				<f:setPropertyActionListener target="#{vagaBean.vaga.empresa}"
					value="#{loginBean.pessoa.empresa}" />
			</p:commandButton>
		</h:panelGrid>
		<h:form id="cadVaga">

			<p:dialog widgetVar="dialogCadastroVaga" header="Dados do Usuario"
				closable="false" resizable="false" modal="true" hideEffect="slide"
				showEffect="clip" draggable="false">

				<h:panelGrid id="displayVaga" columns="3" cellpadding="4"
					style="margin:0 auto;">

					<h:outputLabel value="Título: " />
					<p:inputText id="titulo" value="#{vagaBean.vaga.titulo}"
						title="Insira aqui o título" />
					<p:message for="titulo"></p:message>

					<h:outputLabel value="Requisistos: " />
					<p:inputTextarea value="#{vagaBean.vaga.requisitos}" id="txtReq"
						label="Requisistos" title="Insira aqui os Requisistos" />
					<p:message for="txtReq"></p:message>

					<h:outputLabel value="Atividades: " />
					<p:inputTextarea value="#{vagaBean.vaga.atividades}" id="txtAtiv"
						label="Atividades" title="Insira aqui os Atividades" />
					<p:message for="txtAtiv"></p:message>

					<h:outputLabel value="Benefícios " />
					<p:inputTextarea value="#{vagaBean.vaga.beneficios}" id="txtBen"
						label="Benefícos" title="Insira aqui os Benefícos" />
					<p:message for="txtBen"></p:message>

					<h:outputLabel value="Empresa: "
						rendered="#{loginBean.pessoa.perfil == 'ADM'}" />
					<p:selectOneMenu id="selectBox" value="#{vagaBean.vaga.empresa}"
						rendered="#{loginBean.pessoa.perfil == 'ADM'}"
						converter="empresaConverter" required="true">
						<f:selectItems value="#{empresaBean.empresas}" var="empresa"
							itemLabel="#{empresa.nome}" itemValue="#{empresa}" />
					</p:selectOneMenu>
					<p:message for="selectBox"
						rendered="#{loginBean.pessoa.perfil == 'ADM'}"></p:message>



					<h:outputText></h:outputText>
					<p:commandButton id="btsalvar" value="Salvar"
						rendered="#{vagaBean.vaga.id == null}"
						actionListener="#{vagaBean.gravarVaga}"
						update=":formulario:tabelaVaga displayVaga"
						oncomplete="handleCadastroVagaRequest(xhr, status, args)">
					</p:commandButton>

					<p:commandButton id="btAlterar" value="Alterar"
						rendered="#{vagaBean.vaga.id != null}"
						actionListener="#{vagaBean.alterarVaga}"
						update=":formulario:tabelaVaga displayVaga"
						oncomplete="handleCadastroVagaRequest(xhr, status, args)">
					</p:commandButton>

					<p:commandButton value="Voltar" update="displayVaga"
						process="@this" oncomplete="dialogCadastroVaga.hide()"
						action="#{vagaBean.limparVaga()}">
						<p:resetInput target="displayVaga" />
					</p:commandButton>
				</h:panelGrid>

			</p:dialog>

			<script type="text/javascript">
				function handleCadastroVagaRequest(xhr, status, args) {
					if (args.validationFailed || !args.gravado) {
						jQuery('#dialogCadastroVaga').effect("shake", {
							times : 3
						}, 100);
					} else {
						dialogCadastroVaga.hide();
					}
				}
			</script>

		</h:form>
		<h:form id="formulario">

			<h:outputLabel value="Pesquisar: " />
			<p:inputText value="#{vagaBean.textoPesquisa}" />
			<p:commandButton action="#{vagaBean.pesquisa}" value="Pesquisar"
				update="tabelaVaga"></p:commandButton>
			<br></br>
			<br></br>

			<p:dataGrid id="tabelaVaga" value="#{vagaBean.vagas}" var="vaga"
				columns="1"
				rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'par' : 'impar'}"
				rowIndexVar="rowIx" emptyMessage="nenhum registro encontrado">


				<f:facet name="header">Vagas</f:facet>
				<p:panel header="#{vaga.titulo}"
					rendered="#{vaga.empresa==loginBean.pessoa.empresa or loginBean.pessoa.perfil != 'PARCEIRO'}">

					<h:outputLabel value="Requisistos: " />
					<p:inputTextarea autoResize="true" value="#{vaga.requisitos}" />
					<br></br>
					<h:outputLabel value="Atividades: " />
					<p:inputTextarea readonly="true" value="#{vaga.atividades}" />
					<br></br>
					<h:outputLabel value="Benifícios: " />
					<p:inputTextarea readonly="true" value="#{vaga.beneficios}" />
					<br></br>
					<h:outputLabel value="Empresa: " />
					<p:inputTextarea readonly="true" value="#{vaga.empresa.nome}" />




					<p:column headerText="Ações">
						<div align="center">
							<p:commandLink update=":cadVaga:displayVaga" title="Editar"
								oncomplete="dialogCadastroVaga.show()">
								<f:setPropertyActionListener value="#{vaga}"
									target="#{vagaBean.vaga}" />
								<p:graphicImage value="resources/imagens/editar.png"
									width="24px" height="24px" />
							</p:commandLink>
							<p:commandLink update=":formRemoveVaga:panelRemoveVaga"
								title="Remover" oncomplete="popupRemoveVaga.show()">
								<f:setPropertyActionListener value="#{vaga}"
									target="#{vagaBean.vaga}" />
								<p:graphicImage value="resources/imagens/delete.png"
									width="24px" height="24px" />
							</p:commandLink>
						</div>
					</p:column>
				</p:panel>

			</p:dataGrid>
		</h:form>

		<h:form id="formRemoveVaga">
			<p:dialog header="Têm certeza que deseja apagar?"
				widgetVar="popupRemoveVaga" resizable="false" id="popupRemoveVaga"
				showEffect="fade" hideEffect="explode" closable="false" modal="true">

				<p:panel id="panelRemoveVaga" columns="2">

					<p:commandButton value="Sim, remover"
						action="#{vagaBean.removerVaga}" update=":formulario:tabelaVaga"
						oncomplete="popupRemoveVaga.hide()" />

					<p:commandButton value="Não remover"
						action="#{vagaBean.limparVaga}" onclick="popupRemoveVaga.hide()" />
				</p:panel>
			</p:dialog>
		</h:form>

	</ui:define>
</ui:composition>
</html>